<?php
ob_start();

include_once "header.php";

?>

<tr>
	<th>Search Killboard</th>
</tr>

<tr>

	<td>
		<form action="search.php" method="post">
		<table cellpadding="5" cellspacing="2" id="searchTable">
		<tr>
			<td style="text-align:right;">Search String:</td>
			<td><input type="text" class="text-box" name="searchString" value=""/></td>
			<td style="text-align:right;">Search For:</td>
			<td>
				<select class="text-box" name="searchType">
				<option value="players">Players</option>
				<option value="corps">Corporations</option>
				<option value="alliances">Alliances</option>
				<option value="systems">Systems</option>
				</select>
			</td>
			<td><input type="submit" name="search" value="Search" /></td>
		</tr>
		</table>
		</form>
	</td>
	
</tr>

<?php

if (isset($_POST['searchString']))
{
	?>
	<tr>
		<th>Search Results</th>
	</tr>
	
	<tr>
		<td>
		<ul>
		<?php
		
		// Search Results Here
		
		if (strlen($_POST['searchString']) < 3)
		{
			echo ("Please enter at least 3 search characters");
		}
		else
		{
		
			$searchString = "%" . $_POST['searchString'] . "%";
			
			$searchType = $_POST['searchType'];
			
			switch ($searchType)
			{
				case "players":
				
					$sql = "SELECT * FROM `kb_player` WHERE `playerName` LIKE '$searchString'";			
					$queryResult = mysql_query($sql);
					while ($playerDetails = mysql_fetch_row($queryResult))
					{
						printf ("<li><a href=\"pkills.php?id=%s\">%s</a></li>", $playerDetails[0], $playerDetails[1]);	
					}
					
				break;
				
				case "corps":
				
					$sql = "SELECT * FROM `kb_corp` WHERE `corpName` LIKE '$searchString'";			
					$queryResult = mysql_query($sql);
					
					while ($corpDetails = mysql_fetch_row($queryResult))
					{
						printf ("<li><a href=\"ckills.php?id=%s\">%s</a></li>", $corpDetails[0], $corpDetails[1]);	
					}
				
				break;
				
				case "alliances":
				
					$sql = "SELECT * FROM `kb_alliance` WHERE `allianceName` LIKE '$searchString'";			
					$queryResult = mysql_query($sql);
					while ($allianceDetails = mysql_fetch_row($queryResult))
					{
						printf ("<li><a href=\"akills.php?id=%s\">%s</a></li>", $allianceDetails[0], $allianceDetails[1]);	
					}
					
				break;
					
				default:
					echo ("There was an error while searching, please try again later");
			}

		}
			
		?>
		</ul>
		</td>
	</tr>
	
	<?php
}

require "footer.php";

ob_end_flush();
?>